package ControlLayer;

import java.util.ArrayList;
import java.util.Iterator;

import ModelLayer.Product;
import ModelLayer.ProductContainer;
import ModelLayer.Supplier;

/**
 * This is the Product Controller, all business logic goes here, consume it from
 * the UI
 * 
 * @author frankeskelund, Tobias, Kim
 *
 */
public class ProductCtr {

	private ProductContainer container;

	public ProductCtr() {
		container = ProductContainer.getInstance();
		container.addDummyProducts();
	}

	/**
	 * Find a product from container by barcode
	 * 
	 * @param barcode
	 *            insert barcode as string
	 * @return Product object
	 */
	public Product findProduct(String barcode) {
		return container.findProduct(barcode);
	}

	/**
	 * find low in stcok
	 */

	public ArrayList<Product> findLowInStock() {
		ArrayList<Product> products = container.getAllProducts();

		Iterator<Product> iterator = products.iterator();
		while (iterator.hasNext()) {
			Product currentProduct = iterator.next();
			if (currentProduct.getAmountInStock() > currentProduct.getMinStockAmount()) {
				iterator.remove();
			}
		}
		return products;
	}

	/**
	 * @param productNo
	 * @return
	 */
	public Product findProduct(int productNo) {
		// TODO Auto-generated method stub
		return container.findProduct(productNo);
	}
	
	/**
	 * @param productNo
	 * @return
	 */
	public void UpdateProduct(Product newProduct)
	{
		container.updateProduct(newProduct);
	}
}
